package com.wangjiyuan.giftshuo.ui.activity.other.more;

import android.util.Log;

import com.wangjiyuan.giftshuo.bean.more.MoreBean;

import java.util.Map;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by wjy on 2016/11/22.
 */

public class MorePresenter implements MoreContract.MorePresenter {
    private MoreModel moreModel = new MoreModel();
    private MoreContract.MoreView view;
    private Subscription subscribe;

    public MorePresenter(MoreContract.MoreView view) {
        this.view = view;

    }

    @Override
    public void getMoreBean(String id, Map<String, String> map) {
        subscribe = moreModel.getMoreBean(id, map).observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Subscriber<MoreBean>() {
                    @Override
                    public void onCompleted() {
                        subscribe.unsubscribe();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("aaa", e.toString());
                        subscribe.unsubscribe();
                    }

                    @Override
                    public void onNext(MoreBean moreBean) {
                        view.getMoreBean(moreBean);
                    }
                });
    }
}
